class Solution {
    int ret, _target;
public:
    int findTargetSumWays(vector<int>& nums, int target) {
        _target = target;
        dfs(nums, 0, 0);
        return ret;
    }
 
    void dfs(vector<int>& nums, int pos, int path)
    {
        if(pos ==  nums.size())
        {
            if(path == _target)
                ++ret;
            return;
        }
        dfs(nums, pos + 1, path + nums[pos]);  // 加法
        dfs(nums, pos + 1, path - nums[pos]); // 减法
    }
};